<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/bootstraptable/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <div style="width: 1200px;margin: 0 auto;">
        <h5 style="color: #3e79b6">您正在做的业务是：生产管理--产品生产工序设计--产品生产工序设计审核</h5>
    </div>

    <div class="panel panel-default">
        <form id="module_form" class="form-horizontal">
            <div class="panel-heading" style="text-align: right">
                <button type="button" id="preview_btn" class="btn btn-info">预览</button>
                <button type="button" id="submit_btn" class="btn btn-info">确定</button>
                <button type="button" id="fanhui_btn" class="btn btn-info">返回</button>
            </div>
            <div class="panel-body">

                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">设计单编号：</label>
                        <div class="col-sm-8">
                            <input type="text" name="designId" id="designId"
                                   class="form-control text_no_border"
                                   value="">
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">设计人：</label>
                        <div class="col-sm-8">
                            <input type="text" name="designer" id="designer"
                                   class="form-control text_no_border"
                                   value="">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">产品名称：</label>
                        <div class="col-sm-8">
                            <input type="text" name="productName" id="productName"
                                   class="form-control text_bottom_border"
                                   value="">
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">产品编号：</label>
                        <div class="col-sm-8">
                            <input type="text" name="productId" id="productId"
                                   class="form-control text_bottom_border"
                                   value="">
                        </div>
                    </div>
                </div>
                <!--产品生产工序明细表格-->

                <table id="module_details_table"></table>

                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">工时总成本：</label>
                        <div class="col-sm-8">
                            <input type="text" name="costPriceSum" id="costPriceSum"
                                   class="form-control text_bottom_border"
                                   value="">
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">物料总成本：</label>
                        <div class="col-sm-8">
                            <input type="text" name="moduleCostPriceSum" id="moduleCostPriceSum"
                                   class="form-control text_bottom_border"
                                   value="">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">审核人：</label>
                        <div class="col-sm-8">
                            <input class="form-control" id="checker" name="checker"></input>
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">审核时间：</label>
                        <div class="col-sm-8">
                            <input type="text" name="checkTime" id="checkTime" class="form-control"
                                   value="">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">设计要求：</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" id="procedureDescribe" name="procedureDescribe"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>

<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<!--<script type="text/javascript" src="/js/index.js"></script>-->

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    $(function () {
        let id = localStorage.getItem("id")
        console.log("id"+id)

        // 根据id查询对应的产品档案
        $.get("/design/procedure/designProcedureGetId", {"id": id}, function (data) {
            // 表单数据的回显
            $("#designId").val(data.designId)
            $("#designer").val(data.designer)
            $("#productName").val(data.productName)
            $("#productId").val(data.productId)
            $("#costPriceSum").val(data.costPriceSum)
            $("#checker").val(data.checker)
            $("#checkTime").val(data.checkTime)
            $("#procedureDescribe").val(data.procedureDescribe)
            $("#module_form #moduleCostPriceSum").val(data.moduleCostPriceSum)

            let subTotal=null;

            $("#moduleSubtotal").val(subTotal)

            $("#module_details_table").bootstrapTable({
                // 请求方式
                method: "post",
                // 内容类型：如果请求方式是post，内容类型必须是application/x-www-form-urlencoded
                contentType: "application/x-www-form-urlencoded",
                // 请求路径
                url: '/design/procedure/listByIdDetails',
                // 数据行交替样式
                striped: true,
                // 是否是服务器端分页：server表示服务器端，client表示前端分页
                sidePagination: 'server',
                //初始化加载第一页
                pageNumber: 1,
                //是否分页
                pagination:true,
                // 单页记录数，页大小
                pageSize: 1,
                // 分页列表
                pageList: [2, 3, 4, 5],
                //刷新按钮
                // showRefresh:true,
                // 请求参数
                queryParams: function (params) {
                    let obj = {
                        // params.limit获取组件中的页大小
                        // params.offset获取请求数据的起始索引
                        id:id,
                        pageSize: params.limit,
                        pageNo: (params.offset / params.limit) + 1,
                    }
                    return obj;
                },
                // 表格列标题
                columns: [{
                    title: "序号",
                    field: "id",
                    sortable:true
                },{
                    title: "工序名称",
                    field: "procedureName"
                },{
                    title: "工序编号",
                    field: "procedureId",

                },{
                    title: "描述",
                    field: "procedureDescribe"
                },{
                    title: "工时数",
                    field: "labourHourAmount"
                },{
                    title: "工时成本小计(元)",
                    field: "subtotal"
                },{
                    title: "物料成本小计(元)",
                    field: "moduleSubtotal"
                },{
                    title: "审核",
                    field: ""
                }]
            })
        }, "json")
    })

    //返回
    $("#fanhui_btn").click(function (){
        window.location="/procedure/design_procedure_module_queryUI"
    })


    $("#preview_btn").click(function (){
        // 获取所有的数据行对象
        let data = $("#module_form #module_details_table").bootstrapTable("getData")

        //设置物料总成本
        let moduleCostPriceSums=0;

        for (let i=0; i<data.length; i++) {
            //计算金额
            moduleCostPriceSums+= data[i].moduleSubtotal
        }
        $("#module_form #moduleCostPriceSum").val(moduleCostPriceSums)
    })

    $("#submit_btn").click(function (){
        let productId=$("#productId").val()
        $.post("/design/procedure/upd_module_tag","productId="+productId,function (data){
            if(data){
                window.location="/design/design_successUI"
            }
        })
    })
</script>
</body>
</html>